package net;

/** 
 * This class is used in the Net* classes to log network communication related events.
 * You can specify which events you want to be to logged by setting the static flags 
 * variable. You can disable logging by setting flags to NetLogNone. The default value
 * is NetLogAll.
 */
public class NetLogger 
{
	public static final int NetLogAll = (int)(Math.pow(2, 12) - 1);
	public static final int NetLogNone = 0;
	public static final int NetLogLog = 1;
	public static final int NetLogFine = 2;
	public static final int NetLogConnection = 4;
	public static final int NetLogMessage = 8;
	public static final int NetLogService = 16;
	public static final int NetLogWarning = 32;
	public static final int NetLogError = 64;
	public static final int NetLogException = 128;
	public static final int NetLogPing = 256;
	
	public static int flags = NetLogAll;
	public static final int NetLogImportant = NetLogConnection | 
					NetLogWarning | NetLogError | NetLogException | NetLogService;
	
	private static boolean flagSet(int flag){
		return (flag & flags) == flag;
	}
	
	private static void println(String msg) {
		System.out.println(msg);
	}
	
	public static void log(String msg) {if(flagSet(NetLogLog)) println(msg);}
	public static void fine(String msg) {if(flagSet(NetLogFine)) println(msg);}
	
	public static void connection(String msg) {if(flagSet(NetLogConnection)) println(msg);}
	public static void message(String msg) {if(flagSet(NetLogMessage)) println(msg);}
	public static void service(String msg) {if(flagSet(NetLogService)) println(msg);}
	
	public static void warning(String msg) {if(flagSet(NetLogWarning)) println(msg);}
	public static void error(String msg) {if(flagSet(NetLogError)) println(msg);}
	public static void exception(String msg) {if(flagSet(NetLogException)) println(msg);}
	
	public static void ping(String msg) {if(flagSet(NetLogPing)) println(msg);}
}
